#include "Observable.h"

/*-----------------------------------------------------------------------------------------------------
--	FUNCTION:	Observable::Observable () : observers()
--
--	DATE:			April 07, 2010
--
--	REVISIONS		(Date and Description):
--
--	DESIGNER:		Eric Ribeiro
--
--	PROGRAMMER:		Eric Riberiro
--
--      INTERFACE:      Observable::Observable ()
--
--	RETURNS:
--
--	NOTES:
--		Constructor for the oberval
---------------------------------------------------------------------------------------*/
Observable::Observable () : observers()
{
	// Nothing to do here.
}

/*--------------------------------------------------------------------------------------------
--	FUNCTION:	void Observable::addObserver (Observer * observer)
--
--	DATE:			April 07, 2010
--
--	REVISIONS		(Date and Description):
--
--	DESIGNER:		Eric Ribeiro
--
--	PROGRAMMER:		Eric Riberiro
--
--      INTERFACE:      Observable::Observable ()
--
--	RETURNS:
--
--	NOTES:
--		Function to add in item that the we want to observe, it adds into the observers
-------------------------------------------------------------------------------------------------*/
void Observable::addObserver (Observer * observer)
{
	observers.insert(observer);
}


/*-----------------------------------------------------------------------------------------------------
--	FUNCTION:	void Observable::removeObserver (Observer * observer)
--
--	DATE:			April 07, 2010
--
--	REVISIONS		(Date and Description):
--
--	DESIGNER:		Eric Ribeiro
--
--	PROGRAMMER:		Eric Riberiro
--
--      INTERFACE:      Observable::Observable ()
--
--	RETURNS:
--
--	NOTES:
--		Function to remove item that the we no longer want to observe, it adds into the observers
---------------------------------------------------------------------------------------------------------*/
void Observable::removeObserver (Observer * observer)
{
	observers.erase(observer);
}

/*--------------------------------------------------------------------------------------------
--
--	FUNCTION: notifyAll
--
--	Date: April 5, 2010
--
--	REVISIONS (Date and Description):
--
--	DESIGNER: Erick Ribeiro
--
--	PROGRAMMER: Erick Ribeiro
--
--  INTERFACE: void Observable::notifyAll (int eventCode)
--
--      int eventCode: What event occured.
--
--  RETURNS: void
--
--	NOTES: Notifies all objects within the list of the specific event that occured.
--
--------------------------------------------------------------------------------------------*/
void Observable::notifyAll (int eventCode)
{
	std::set<Observer *>::iterator it;

	for (it = observers.begin(); it != observers.end(); it++)
		(*it)->notify(this, eventCode);
}
